﻿using System;

namespace CollegeSim.Domain.Entities
{
    // Author: Ryan Redburn
    // Project: CollegeSim
    // Date: 2/4/2014

    #region [ Updates ]

    // Author: Ryan Redburn
    // Date: 5/6/2014
    // Revisions: Changed Course to reflect 2.0 changes

    #endregion

    /// <summary>
    /// Class used to represent a course. Contains properties, ToString() override.
    /// </summary>
    public class Course
    {
        #region [ Fields ]

        private string _subject;
        private string _number;
        private string _title;
        private int _creditHours;
        private int _contactHours;

        #endregion

        #region [ Properties ]

        // CourseID
        // Set by DB
        public int CourseID { get; set; }

        /// <summary>
        /// Three character course subject abbreviation.
        /// </summary>
        public string Subject
        {
            get { return _subject; }
            set
            {
                if (!String.IsNullOrEmpty(value))
                {
                    if (value.Length == 3)
                    {
                        _subject = value.ToUpper();
                    }
                    else
                    {
                        throw new ArgumentOutOfRangeException("value", "Subject must be three characters in length.");
                    }
                }
                else
                {
                    throw new ArgumentNullException("value", "Subject cannot be null or exmpty.");
                }
            }
        }

        /// <summary>
        /// Three character course number.
        /// </summary>
        public string Number
        {
            get { return _number; }
            set
            {
                if (!String.IsNullOrEmpty(value))
                {
                    if (value.Length == 3)
                    {
                        _number = value;
                    }
                    else
                    {
                        throw new ArgumentOutOfRangeException("value", "Number must be three characters in length.");
                    }
                }
                else
                {
                    throw new ArgumentNullException("value", "Number cannot be null or exmpty.");
                }
            }
        }

        /// <summary>
        /// Course title.
        /// </summary>
        public string Title
        {
            get { return _title; }
            set
            {
                if (!String.IsNullOrWhiteSpace(value))
                {
                    if (value.Length <= 50)
                    {
                        _title = value;
                    }
                    else
                    {
                        throw new ArgumentOutOfRangeException("value", "Title cannot be more than fifty characters in legnth.");
                    }
                }
                else
                {
                    throw new ArgumentNullException("value", "Title cannot be null or empty.");
                }
            }
        }

        /// <summary>
        /// Number of credit hour value.
        /// </summary>
        public int CreditHours
        {
            get { return _creditHours; }
            set
            {
                if (value >= 1 && value <= 6)
                {
                    _creditHours = value;
                }
                else
                {
                    throw new ArgumentOutOfRangeException("value", "CreditHours cannot be less than 1 or greater than 6.");
                }
            }
        }

        /// <summary>
        /// Number of course contact hours.
        /// </summary>
        public int ContactHours
        {
            get { return _contactHours; }
            set
            {
                if (value >= 1 && value <= 6)
                {
                    _contactHours = value;
                }
                else
                {
                    throw new ArgumentOutOfRangeException("value", "ContactHours cannot be less than 1 or greater than 6.");
                }
            }
        }

        /// <summary>
        /// Online course style.
        /// </summary>
        public bool Online { get; set; }

        /// <summary>
        /// Hybrid course style.
        /// </summary>
        public bool Hybrid { get; set; }

        #endregion

        #region [ Constructors ]

        public Course()
        {
            CourseID = 0;
        }

        #endregion

        #region [ Methods ]

        // Overrided ToString() returns basic course information
        public override string ToString()
        {
            return CourseID + " - " + Subject + Number + " - " + Title;
        }

        #endregion
    }
}
